var tempnum=1;
function loopExecute(func,time,loopnum){
	var i=1;
	var interval=setInterval(function(){
		if(i>loopnum){clearInterval(interval);return;}
		setTimeout((func)('abc'+i),time);
		i=i+1;
	},time);
}

//函数1
var tempfunc=function(st){tempnum=tempnum+1;alert(st)};
//函数2
function tempfunc2(st){
	tempnum=tempnum+1;alert(st)
}

function initial(){
	//loopExecute(tempfunc2,1000,3);
	var stu=new Student(20,'wc','男');
	//stu.say();
	var cla=Class_('S1T98',200);
	//cla.say();
}


function runCode(editid){
	var frame_=$("console");
	var doc=null;
	if($('runframe')==null){
		frame_.innerHTML='<iframe id="runframe"></iframe>';
		doc=$('runframe').contentDocument;
		var div_=$(editid).value;
		doc.open();
		doc.write(div_);
		doc.close();
	}
	else{
		doc=$('runframe').contentDocument;
		doc.getElementById('main').innerHTML=$(editid).value;
	}
	
}
var _selstr;
function tojs(id){
	var selstr=getTextFieldSelection($(id));
	_selstr=selstr;
	$(id).value=$(id).value.replace(selstr,"<script>\n"+selstr+"</script>\n");
}
function $(id){
	return document.getElementById(id);
}

function getTextFieldSelection(e) {
    if (e.selectionStart != undefined && e.selectionEnd != undefined) {
        var start = e.selectionStart;
        var end = e.selectionEnd;
        return e.value.substring(start, end);
    }
    else return "";  // Not supported on this browser
}

function getSelectedText() {
    if (window.getSelection) {
        // This technique is the most likely to be standardized.
        // getSelection() returns a Selection object, which we do not document.
        return window.getSelection().toString();
    }
    else if (document.getSelection) {
        // This is an older, simpler technique that returns a string
        return document.getSelection();
    }
    else if (document.selection) {
        // This is the IE-specific technique.
        // We do not document the IE selection property or TextRange objects.
        return document.selection.createRange().text;
    }
}


/*
 *创建方式1
 *JavaScript 定义对象和类
 *
 *类就是一个模版
 */
function Student(age,name,sex){
	
	//使用this跟加的属性是就是动态的属性
	this.age=age;
	this.name=name;
	this.sex=sex;
	
	if(typeof Student._initialized=='undefined'){
		//类名.prototype后的属性就是静态的属性，可以是值可以是对象可以是方法
		Student.prototype.say=function(){
			var syastr='my name is '+this.name+' and my age is '+this.age+' and my sex is '+this.sex;
			alert(syastr);
		}
	}
	Student._initialized =true; 
}

/*
 *创建方式1结束
 */

/*
 *创建方式2
 *工厂方式创建对象
 *
 */
function Class_(classname,studentnum){
	var classobj=new Object;
	classobj.classname=classname;
	classobj.studentnum=studentnum;
	classobj.say=function(){
		var syastr='my class is '+this.classname+' and my class studentnum is '+this.studentnum;
		alert(syastr);
	}
	return classobj;
}

/*
 *创建方式1结束
 */
